package com.example.mydownloader.ui.main

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.mydownloader.data.main.MainDataSource
import com.example.mydownloader.data.main.MainRepository

/**
 * @Author: Wallace
 * @Description: 文件描述
 * @Date: 2022/1/31 18:18
 * @Modified: By yyyy-MM-dd
 */
class MainViewModelFactory : ViewModelProvider.Factory {

    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
            return MainViewModel(
                mainRepository = MainRepository(
                    mainDataSource = MainDataSource()
                )
            ) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}